import java.util.*;
public class grafo {
    private int Vcnt, Ecnt;
    private boolean digraph;
    private class Node
    {
        int v; 
        Node next;
        Node(int x, Node t) 
        {
            v = x; 
            next = t; 
        }
    }
    private Node adj[];
    
    //Constructor
    grafo(int V, boolean flag)
    {
        Vcnt = V;
        Ecnt = 0;
        digraph = flag;
        adj = new Node[V];
    }
    int V() 
    {
        return Vcnt; 
    }
    int E()
    {
        return Ecnt; 
    }
    boolean directed() 
    {
        return digraph; 
    }
    void insert(Eje e)
    { 
        int v = e.v(), w = e.w();
        adj[v] = new Node(w, adj[v]);
        if (!digraph) 
            adj[w] = new Node(v, adj[w]);
        Ecnt++;
    }
    public boolean Adyacente(int ni, int nj)
    {
        return conectados(adj[ni], nj);
    }
    private boolean conectados(Node ni, int nj)
    {
        Node prox=ni;
        while (prox!=null)
        {
            if (prox.v==nj) return true;
            prox=prox.next;
        }
        return false;
    }
}



